package com.acmuno.greenchili;

import org.json.me.JSONException;
import org.json.me.JSONObject;
import org.json.me.JSONStringer;
import java.util.Scanner;
/*	Implement in getMessage() for user input.
*	Also need to include google maps dependency here for gps latitude long altitude calculations,
*	and semantic method checks for the setMessage method (such as limit_views key if false getViewLimit return null).
*/

@SuppressWarnings("unused")
public class LingerMessage {
	
	private String mssg;
	JSONObject jsonData;

	public LingerMessage(){
	}
	
	public LingerMessage(String message) {
		this.mssg = message;
	}
	
	public String parseMessage(){
		try {
			jsonData = new JSONObject(mssg);
			JSONObject jsonResult = new JSONObject(jsonData.getString("data"));
			JSONObject jsonMessage = new JSONObject(jsonResult.getString("message"));
			mssg = jsonMessage.toString();
			
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}

	public void setMessage() {
		JSONStringer js = new JSONStringer();
		
		try {
			
			js.object().key("hash").value(getHash()).key("data").object()
			.key("id").value(getId()).key("location").object()
			.key("latitude").value(getLatitude())
			.key("longitude").value(getLongitude())
			.key("altitude").value(getAltitude())
			.endObject()
			.key("message").value(getMessage()).key("has_life").value(hasLife()).key("life").value(getLife())
			.key("limit_views").value(getLimitBool()).key("view_limit").value(getViewLimit()).endObject();
			
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		this.mssg = js.toString();
	}

	private int getViewLimit() {
		return 1000000;
	}

	private boolean getLimitBool() {

		return true;
	}

	private int getLife() {
		return 10000000;
	}

	private static boolean hasLife() {
			
		return true;
	}

	private static String getMessage() {
		//implement scanner to get user message for the addMessage method in URLQuery class
		
		return "This Is A Linger Message.";
	}

	private static double getAltitude() {

		return 10.0;
	}

	private static double getLongitude() {

		return 16.6664;
	}

	private static double getLatitude() {
		return 15.1245;
	}

	private static String getId() {

		return "abcde";
	}

	private static String getHash() {
		return "#12345";
	}
	
	@Override
	public String toString(){
		return mssg;
	}	
}
